package patrol.mobile.com.mobilepatrol.activity.yanghuke;

import android.content.Intent;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.activity.bridge.BridgeListActivity;
import patrol.mobile.com.mobilepatrol.activity.culvert.CulvertListActivity;
import patrol.mobile.com.mobilepatrol.activity.office.HomeDataHelper;
import patrol.mobile.com.mobilepatrol.activity.office.OtherBusinessActivity;
import patrol.mobile.com.mobilepatrol.activity.office.OtherBusinessSearchActivity;
import patrol.mobile.com.mobilepatrol.activity.road_block.RoadBlockActivity;
import patrol.mobile.com.mobilepatrol.activity.road_survey.TrafficInvestActivity;
import patrol.mobile.com.mobilepatrol.activity.route_query.RouteActivity;
import patrol.mobile.com.mobilepatrol.activity.route_query.TotalRouteActivity;
import patrol.mobile.com.mobilepatrol.activity.track.TrackListActivity;
import patrol.mobile.com.mobilepatrol.activity.yanghuke.lukuangxinxi.LuKuangXinXiActivity;
import patrol.mobile.com.mobilepatrol.activity.yanghuke.niandufeiyong.NianDuFeiyongActivity;
import patrol.mobile.com.mobilepatrol.activity.yanghuke.zuoyeshangbao.ZuoyeListActivity;
import patrol.mobile.com.mobilepatrol.activity.yanghuke.zuoyefenbu.ZuoyeFenBuActivity;
import patrol.mobile.com.mobilepatrol.bean.GridViewAddTitleBean;
import patrol.mobile.com.mobilepatrol.bean.MenuBean;
import patrol.mobile.com.mobilepatrol.bean.MenuConstants;
import patrol.mobile.com.mobilepatrol.manager.UserManager;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.view.OnGridViewAddTitleLisener;
import patrol.mobile.com.mobilepatrol.widget.GridViewAddTitleLayout;

/**
 * Created by z on 2018/9/7.
 * Des: 养护科室主页面
 */

public class YangHuActivity extends BaseActivity implements View.OnClickListener, OnGridViewAddTitleLisener {
    @BindView(R.id.firstGridView)
    GridViewAddTitleLayout firstGridView;
    @BindView(R.id.secondGridView)
    GridViewAddTitleLayout secondGridView;
    @BindView(R.id.thirdGridView)
    GridViewAddTitleLayout thirdGridView;
//    private int[] img1 = new int[]{R.mipmap.l6, R.mipmap.l4, R.mipmap.l1, R.mipmap.l3, R.mipmap.l5, R.mipmap.l6, R.mipmap.l4, R.mipmap.l1};
//    private int[] img2 = new int[]{R.mipmap.l2, R.mipmap.l1, R.mipmap.l3, R.mipmap.l4, R.mipmap.l2, R.mipmap.l3};
//    private int[] img3 = new int[]{R.mipmap.l6};
    private List<MenuBean> menuBeanList;
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_yanghuke;
    }

    @Override
    public void initView() {
        super.initView();
        iv_back.setVisibility(View.VISIBLE);
        tv_center_title.setVisibility(View.VISIBLE);
    }

    @Override
    public void initData() {
        super.initData();
        menuBeanList= (List<MenuBean>) getIntent().getSerializableExtra(MenuConstants.MENU_DATA);
        tv_center_title.setText(R.string.title_yanghuguanli);
        firstGridView.setTitle(MenuConstants.YHGL_TOP_TITLES[0]);
        secondGridView.setTitle(MenuConstants.YHGL_TOP_TITLES[1]);
        thirdGridView.setVisibility(View.GONE);
//        thirdGridView.setTitle("其他业务");
        firstGridView.setGridViewAddTitleBeans(HomeDataHelper.getGridData(MenuConstants.YHGL_CHILD_TITLES_1,MenuConstants.YHGL_CHILD_IMGS_1), menuBeanList);
        secondGridView.setGridViewAddTitleBeans(HomeDataHelper.getGridData(MenuConstants.YHGL_CHILD_TITLES_2,MenuConstants.YHGL_CHILD_IMGS_2), menuBeanList);
//        thirdGridView.setGridViewAddTitleBeans(geThirdData(), menuBeanList);
    }

    @Override
    public void setListener() {
        iv_back.setOnClickListener(this);
        firstGridView.setOnItemClickListener(this);
        secondGridView.setOnItemClickListener(this);
        thirdGridView.setOnItemClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                CommonUtil.exitActivityAndBackAnim(this, true);
                break;
        }
    }

//    /**
//     * 设置第一块数据
//     */
//    private List<GridViewAddTitleBean> getFristData() {
//        List<GridViewAddTitleBean> list = new ArrayList<>();
//        for (int i = 0; i < getResources().getStringArray(R.array.yanghuke_title1).length; i++) {
//            GridViewAddTitleBean gridViewAddTitleBean = new GridViewAddTitleBean();
//            gridViewAddTitleBean.setTitle(getResources().getStringArray(R.array.yanghuke_title1)[i]);
//            gridViewAddTitleBean.setImage(img1[i]);
//            list.add(gridViewAddTitleBean);
//        }
//        return list;
//    }

//    /**
//     * 设置第二块数据
//     */
//    private List<GridViewAddTitleBean> geSecondData() {
//
//        List<GridViewAddTitleBean> list = new ArrayList<>();
//        for (int i = 0; i < getResources().getStringArray(R.array.yanghuke_title2).length; i++) {
//            GridViewAddTitleBean gridViewAddTitleBean = new GridViewAddTitleBean();
//            gridViewAddTitleBean.setTitle(getResources().getStringArray(R.array.yanghuke_title2)[i]);
//            gridViewAddTitleBean.setImage(img2[i]);
//            list.add(gridViewAddTitleBean);
//        }
//        return list;
//    }

    /**
     * 设置第二块数据 third
     */
//    private List<GridViewAddTitleBean> geThirdData() {
//        List<GridViewAddTitleBean> list = new ArrayList<>();
//        GridViewAddTitleBean gridViewAddTitleBean = new GridViewAddTitleBean();
//        gridViewAddTitleBean.setTitle("其他业务");
//        gridViewAddTitleBean.setImage(R.mipmap.other);
//        list.add(gridViewAddTitleBean);
//        return list;
//    }

    @Override
    public void onLisener(View view, int postion) {
        switch (view.getId()) {
            case R.id.firstGridView:
                switch (postion) {
                    case 0://路线查询
                        if (UserManager.getUser().orgtype.equals("总局")) {
                            Intent intent = new Intent(this, TotalRouteActivity.class);
                            intent.putExtra("from", 1);
                            startActivity(intent);
                            CommonUtil.openNewActivityAnim(this, false);
                        } else {
                            Intent intent = new Intent(this, RouteActivity.class);
                            intent.putExtra("from", 1);
                            startActivity(intent);
                            CommonUtil.openNewActivityAnim(this, false);
                        }
                        break;
                    case 1://桥梁信息
                        startActivity(BridgeListActivity.class);
                        break;
                    case 2://涵洞信息
                        startActivity(CulvertListActivity.class);
                        break;
                    case 3://作业分区
                        startActivity(ZuoyeFenBuActivity.class);
                        break;
                    case 4:
                        startActivity(RoadBlockActivity.class);
                        break;
                    case 5://路况信息
                        startActivity(LuKuangXinXiActivity.class);
                        break;
                    case 6://其他业务查询
//                        ToastUtils.showToast("其他业务查询待开发");
                        startActivity(OtherBusinessSearchActivity.class);//其它业务查询
                        break;
                    case 7:
                        startActivity(NianDuFeiyongActivity.class);
                        break;
                }
                break;
            case R.id.secondGridView:
                switch (postion) {
                    case 0:
                        startActivity(TrafficInvestActivity.class);
                        CommonUtil.openNewActivityAnim(this, false);
                        break;
                    case 1:
                        startActivity(TrackListActivity.class);
                        CommonUtil.openNewActivityAnim(this, false);
                        break;
                    case 2:
                        startActivity(BridgeListActivity.class);
                        CommonUtil.openNewActivityAnim(this, false);
                        break;
                    case 3:
                        startActivity(CulvertListActivity.class);
                        CommonUtil.openNewActivityAnim(this, false);
                        break;
                    case 4:
                        startActivity(RoadBlockActivity.class);
                        CommonUtil.openNewActivityAnim(this, false);
                        break;
                    case 5:
                        startActivity(ZuoyeListActivity.class);
                        break;
                }
                break;
            case R.id.thirdGridView:
                startActivity(OtherBusinessActivity.class);//其他业务查询
                break;
        }
    }
}
